package imgshare.service.impl;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import imgshare.mapper.NotificationMapper;
import imgshare.model.Notification;
import imgshare.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotificationServiceImpl implements NotificationService {

    @Autowired
    private NotificationMapper notificationMapper;

    private static final Log log = LogFactory.get();

    @Override
    public void create(Notification notification) {
        int rowChanged = notificationMapper.insertSelective(notification);
        if (rowChanged == 0) {
            log.warn("notificationMapper.insertSelective({})未生效",notification);
        }
    }

    @Override
    public List<Notification> findByReceiverId(Integer userId) {
        return notificationMapper.selectByReceiverId(userId);
    }

    @Override
    public int countUnreadNoticeByReceiverId(Integer receiverId) {
        return notificationMapper.countUnreadNoticeByReceiverId(receiverId);
    }

    @Override
    public void update(Notification notification) {
        notificationMapper.updateByReceiverId(notification.getReceiverId());
    }
}
